<?php
    $url = new Url();
    $arr_status = LoadConfig::$status;
    $arr_position = LoadConfig::$position;
?>
<script type="text/javascript" src="<?php echo Yii::app()->params['tiny_url_cp'];?>js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['static_url_cp'];?>js/tinymce_submit.js"></script>
<script type="text/javascript">
    function ajaxSaveEvent(){
        tinyMCE.triggerSave();
        var strUrl = "<?=$url->createUrl("systemNews/ajaxSaveNews"); ?>";
        $.ajax({
            type: "POST",
            url: strUrl,
            data: {
                title:$("#title").val(),
                type:$("#type").val(),
                introtext:$("#introtext").val(),
                description:$("#description").val(),
                status:$("#status").val(),
            },
            success: function(msg){
                if(msg == 1){
                    alert('Thêm mới thành công');
                    window.location = '<?php echo $url->createUrl("systemNews/index")?>';
                }else{
                    $("#show_error").html(msg);
                }
            },
            beforeSend:function(){
                $("#button_save").attr("disabled","disabled");
            },
            complete:function(){
                $("#button_save").removeAttr("disabled"); 
            }            
        });
    }
</script>
<div class="main clearfix">
    <div class="box clearfix bottom30">
    <form action="" name="form">
        <ul class="form4">
            <li class="clearfix"><label><strong>Tiêu đề</strong>:</label>
                <div class="filltext">
                    <input type="text" style="width:360px" value="" id="title"> 
                </div>
            </li>
            
            <li class="clearfix"><label><strong>Vị trí hiển thị </strong>:</label>
                <div class="filltext">
                     <select style="width:203px;" id="type">
                        <?php foreach($arr_position as $key=>$value){?>
                            <option value="<?php echo $key;?>"><?php echo $value?></option>
                            <?php }?>
                    </select>
                </div>
            </li>
            
            <li class="clearfix"><label><strong>Trạng thái</strong>:</label>
                <div class="filltext">
                    <select style="width:203px;" id="status">
                        <?php foreach($arr_status as $key=>$value){?>
                            <option value="<?php echo $key;?>"><?php echo $value?></option>
                            <?php }?>
                    </select>
                </div>
            </li>
           
            <li class="clearfix"><label><strong>Tóm tắt</strong>:</label>
                <div class="filltext">
                    <textarea cols="5" rows="5" style="width:624px; height:120px" id="introtext"></textarea>
                </div>
            </li>
            <li class="clearfix"><label><strong>Chi tiết</strong>:</label>
                    <div class="filltext">
                        <textarea cols="5" rows="5" style="width:400px; height:120px" id="description"></textarea>
                    </div>
                </li>
           
            <li class="clearfix"><label>&nbsp;</label>
                <div class="filltext">
                    <input id="button_save" type="button" value=" Thêm mới " class="btn-bigblue" onclick="ajaxSaveEvent();"> 
                    &nbsp;
                    <input onclick="history.go(-1)" type="button" value=" Quay lại " class="btn-bigblue">
                </div>
            </li>
            <li class="clearfix"><label>&nbsp;</label>
                <div class="filltext" style="color: red;" id="show_error"></div>
            </li>
        </ul>
        </form>

    </div>
</div>